package action.activity;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import myUtils.MemberInfo;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.User;
import service.ActivityService;
import service.OrgService;
/**
 *
 * @author HX
 */
public class AskForLeaveAcitivityAction extends ActionSupport implements ServletRequestAware{
    private HttpServletRequest request;
    private ActivityService activityService;
    private OrgService orgService;
    private int userId;
    private String mailTitle;
    private String mailToIds;

    @Override
    public String execute()
    {
        int orgId;
        int activityId;
        String msg;
        if (ActionContext.getContext().getSession().get("user") == null) {
            msg = "you should login first";
            request.setAttribute("msg", msg);
            return ERROR;
         }
        userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
        if(request.getParameter("orgId")==null)
         {
             msg="no org id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
        orgId = Integer.parseInt(request.getParameter("orgId"));
        if(request.getParameter("activityId")==null)
         {
             msg="no activity id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
        activityId = Integer.parseInt(request.getParameter("activityId"));
        activityService.askForLeave(activityId, userId);
        mailToIds = String.valueOf(orgService.getManagerOfOrg(orgId).getId());
        mailTitle = "[活动请假]" + activityService.getActivity(activityId).getName();
        
        return SUCCESS;

    }

    public void setActivityService(ActivityService activityService)
    {
        this.activityService=activityService;
    }

    public ActivityService getActivityService()
    {
        return this.activityService;
    }

    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public OrgService getOrgService()
    {
        return this.orgService;
    }

    public String getMailTitle() {
        return mailTitle;
    }

    public void setMailTitle(String mailTitle) {
        this.mailTitle = mailTitle;
    }

    public String getMailToIds() {
        return mailToIds;
    }

    public void setMailToIds(String mailToIds) {
        this.mailToIds = mailToIds;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }
}



